<template>
  <div class="setting-dialog-container">
    <div class="app-container">
      <el-dialog
        title="角色操作"
        :visible.sync="this.dialogFormVisible"
        :before-close="handleClose"
      >
        <el-form ref="roleForm" label-width="120px" :model="form" :rules="rules">
          <el-form-item label="角色名称" prop="name">
            <el-input v-model="form.name" style="width: 80%" placeholder="请输入角色名称" />
          </el-form-item>
          <el-form-item label="角色描述" prop="description">
            <el-input
              v-model="form.description"
              type="textarea"
              :rows="2"
              style="width: 80%"
              placeholder="请输入角色描述"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="handleConfirm">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  name: 'setting-dialog',
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },
    employeesList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      form: {
        description: '', // 角色描述
        name: '', // 角色名称
      },
      rules: {
        name: [
          { required: true, message: '角色名称不能为空', trigger: 'blur' },
          { min: 2, max: 10, message: '角色名称要求2-10个字符', trigger: 'blur' },
        ],
        description: [
          { required: true, message: '角色描述不能为空', trigger: 'blur' },
          { min: 1, max: 50, message: '角色描述要求1-50个字符', trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
    handleClose() {
      this.form = {
        description: '', // 角色描述
        name: '', // 角色名称
      }
      this.$emit('update:dialogFormVisible', false)
    },
    handleConfirm() {
      this.$refs.roleForm.validate((valid) => {
        if (valid) {
          this.$emit('addRole', this.form)
          this.form = {
            description: '', // 角色描述
            name: '', // 角色名称
          }
          this.handleClose()
        } else {
          return false
        }
      })
    },
  },
}
</script>

<style lang="less" scoped>
</style>
